package com.hipmarket.platform.security

import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.security.core.Authentication
import org.springframework.security.core.GrantedAuthority
import java.lang.ClassCastException

open class JwtAuthenticationUser(
        open val primaryId: String = "",
        open val userPermissions: List<String> = listOf(),
        open val userRoles: List<String> = listOf(),
        open val userDetails: Any = ""
): Authentication {

    @JsonIgnore
    private val isAuthenticated = true

    @JsonIgnore
    override fun getName(): String {
        return primaryId
    }

    @JsonIgnore
    override fun getAuthorities(): MutableCollection<out GrantedAuthority>? {
        return null
    }

    @JsonIgnore
    override fun getPrincipal(): Any {
        return primaryId
    }

    @JsonIgnore
    override fun getCredentials(): Any? {
        return null
    }

    @JsonIgnore
    override fun getDetails(): Any {
        return userDetails
    }

    @JsonIgnore
    override fun setAuthenticated(p0: Boolean) {
        return
    }

    @JsonIgnore
    override fun isAuthenticated(): Boolean {
        return true
    }

    fun castUserDetails(clazz: Class<*>, objectMapper: ObjectMapper) {
//        userDetails = objectMapper.convertValue(userDetails, clazz)
    }

}